/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import Entity.Owner;
import Entity.Pet;
import Services.PetService;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author microraptor
 */
public class ControlPet {
    EntityManagerFactory emf;
        EntityManager em;

    public ControlPet() {
        emf = Persistence.createEntityManagerFactory("HPVAS-2013-1-BPU");
    }
    
    public void crearPet (String nombre, String species, int age, float weight, String picture, Owner owner){
        //em = emf.createEntityManager();
        PetService ps = new PetService(emf);
        Pet p = new Pet(nombre, species, age, weight, picture, owner);
        ps.crear(p);
    }
    
    public void editPet (Pet pet) throws Exception{
        PetService ps = new PetService(emf);
        ps.edit(pet);
    }
    
    public void removePet (Long id){
        PetService vs = new PetService(emf);
        try {
            vs.destroy(id);
        }catch(Exception e ){
            
        }
    }
    
    public List<Pet> readAllPets (){
        PetService vs = new PetService(emf);
        return vs.findPetEntities();
    }
    
    public Pet readPet(Long id){
        PetService ps = new PetService(emf);
        return ps.findPet(id);
    }

    
    
    
}
